package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.Box;
import cn.yuanqiao.archive.storeRoom.domain.TechnicalTreatment;
import cn.yuanqiao.archive.storeRoom.domain.TechnicalTreatmentVo;
import cn.yuanqiao.archive.storeRoom.domain.UpDownShelves;
import cn.yuanqiao.archive.storeRoom.service.TechnicalTreatmentService;

import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 档案技术处理 前端控制器
 * </p>
 *
 * @author GW
 * @since 2024-04-16
 */
@Slf4j
@RestController
@RequestMapping("/archive/technical-treatment")
public class TechnicalTreatmentController extends BaseController {

    @Autowired
    private TechnicalTreatmentService technicalTreatmentService;

    /**
     * get批次号
     */
    @GetMapping("/getBatchNumber")
//    @RequiresPermissions("archive:technical-treatment:getBatchNumber")
    public AjaxResult getBatchNumber() {
        log.info("Request received to generate batch number");
        Map<String, String> map = new HashMap<>();
        map.put("batchNumber", new SimpleDateFormat("yyyyMMddHHmmssmsus").format(new Date()));
        log.info("Generated batch number: {}", map.get("batchNumber"));
        return success(map);
    }

    /**
     * 新增
     */
    @PostMapping("/save")
//    @RequiresPermissions("archive:technical-treatment:save")
    public AjaxResult save(@RequestBody TechnicalTreatment technicalTreatment) {
        log.info("Saving TechnicalTreatment with batch number: {}", technicalTreatment.getBatchNum());
        return toAjax(technicalTreatmentService.save(technicalTreatment));
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove")
//    @RequiresPermissions("archive:technical-treatment:remove")
    public AjaxResult remove(@RequestBody JSONObject object) {
        return toAjax(technicalTreatmentService.removeById(object));
    }


    /**
     * 修改
     */
    @PutMapping("/update")
//    @RequiresPermissions("archive:technical-treatment:update")
    public AjaxResult update(@RequestBody TechnicalTreatment technicalTreatment) {
        return toAjax(technicalTreatmentService.updateById(technicalTreatment));
    }

    /**
     * 查询id
     */
    @GetMapping("/findById")
//    @RequiresPermissions("archive:technical-treatment:findById")
    public AjaxResult findById(Long id, String sjType) {
        TechnicalTreatmentVo byId = technicalTreatmentService.findById(id, sjType);
        return success(byId);
    }

    /**
     * 查询id
     */
    @GetMapping("/findByDa")
//    @RequiresPermissions("archive:technical-treatment:findByDa")
    public TableDataInfo taskType(Long id, String sjType, String taskType) {
        List<UpDownShelves> list = technicalTreatmentService.findByDa(id, sjType, taskType);
        return getDataTable(list);
    }

    /**
     * 调档中档案查询
     */
    @PostMapping("/findByConditionToDangAn")
//    @RequiresPermissions("archive:technical-treatment:findByConditionToDangAn")
    public TableDataInfo findByConditionToDangAn(@RequestBody Box box) {
        startPage();
        List<UpDownShelves> list = technicalTreatmentService.getDangAnList(box);
        return getDataTable(list);
    }

    /**
     * 分页查询
     */

    @PostMapping("/findByPage")
//    @RequiresPermissions("archive:technical-treatment:findByPage")
    public TableDataInfo findByPage(@RequestBody TechnicalTreatment technicalTreatment) {
        startPage();
        List<TechnicalTreatmentVo> list = technicalTreatmentService.findByPage(technicalTreatment);
        return getDataTable(list);
    }

    /**
     * 添加至处理单 移除 上下架按钮
     */
    @PutMapping("/updateStatus")
//    @RequiresPermissions("archive:technical-treatment:updateStatus")
    public AjaxResult updateStatus(@RequestBody JSONObject object) {
        return toAjax(technicalTreatmentService.updateStatus(object));
    }

}

